﻿using System.Diagnostics;
using HalalCheck.CustomViews;
using HalalCheck.Resources;
using HalalCheck.ViewModels;
using SpotOffer.Resource;
using Xamarin.Forms;
using XLabs.Forms.Controls;

namespace HalalCheck.View
{
    public class SalahPage : BasePage
    {
        public SalahPage()
        {
            Title = HalalStrings.Salah;
           
            

            var layout = new RelativeLayout
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            var halalchecklogo = new Image
            {
                Source = "centerlogo.png"
            };
            layout.Children.Add(halalchecklogo, Constraint.RelativeToParent((p) => (p.Bounds.Width - 200) / 2), Constraint.RelativeToParent((p) => (p.Bounds.Height - 200) / 2), Constraint.RelativeToParent((p => 200)), Constraint.RelativeToParent((p) => 200));

            var halalLabelBackground = AppViews.WhiteRounded();
            layout.Children.Add(halalLabelBackground, Constraint.Constant(AppMargins.ItemPadding), Constraint.Constant(AppMargins.ItemPadding), Constraint.RelativeToParent((p) => p.Bounds.Width - AppMargins.ItemPadding * 2), Constraint.RelativeToParent((p) => p.Bounds.Height - AppMargins.ItemPadding*2 ));


            var salah = new ExtendedLabel
            {
                TextColor = AppColors.OrigDarkBlue,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center,
                FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
            };
            salah.SetBinding(Label.TextProperty, new Binding("Salat.location"));
            layout.Children.Add(salah, Constraint.Constant(AppMargins.ItemMargin), Constraint.Constant(AppMargins.ItemMargin), Constraint.RelativeToParent((p) => p.Bounds.Width - AppMargins.ItemMargin * 2), Constraint.Constant(20));

            var SalatLabel = new Label
            {
                TextColor = AppColors.OrigDarkBlue,
                XAlign = TextAlignment.Start,
                YAlign = TextAlignment.Center,
               // FontAttributes = FontAttributes.Bold,
                FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),           
            };
            SalatLabel.SetBinding(Label.TextProperty, "SalatGenerated");

            layout.Children.Add(SalatLabel, Constraint.Constant(AppMargins.ItemMargin*2), Constraint.RelativeToView(salah, (p, s) => s.Bounds.Bottom), Constraint.RelativeToParent((p) => p.Bounds.Width - AppMargins.ItemMargin * 2), Constraint.RelativeToView(salah, (p, s) => 200));
           


			var map = new CircleImage
            {
                Aspect = Aspect.AspectFit,
                
              //  BackgroundColor = AppColors.White.MultiplyAlpha(0.95),
            };
            map.SetBinding(CircleImage.SourceProperty, "Salat.map_image");

          /*  map.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == "IsLoading")
                {
                    if (map.IsLoading)
                    {
                        layout.Opacity = 0;
                    }
                    else
                    {
                        layout.FadeTo(1, 1500);
                    }

                }
            };*/

            layout.Children.Add(map, Constraint.Constant(AppMargins.ItemMargin),
                Constraint.RelativeToView(SalatLabel, (p, s) => s.Bounds.Bottom), Constraint.RelativeToParent((p) => p.Bounds.Width - AppMargins.ItemMargin * 2), Constraint.RelativeToView(SalatLabel, (p, s) => p.Bounds.Height - s.Bounds.Bottom - AppMargins.ItemMargin));

            var qibla = new Image
            {
                Aspect = Aspect.AspectFit,
                Source="salah.png"
            };

            Content = layout;
        }



  
    }
}
